import glob
import pdb
import pandas as pd

if  __name__ == '__main__':
    
    name2index = {'anger':0,'disgust':1,'fear':2,'happy':3,'sadness':4,'surprise':5}
    names = glob.glob('BU3DFE0_1_processed_data/train/*/*.csv')
    all_datas = {'image_id':[],'label':[]}
    for name in names:
        data = pd.read_csv(name)
        img_name = name.replace('BU3DFE0_1_processed_data','BU3DFE0_1')
        img_name = img_name.replace('.csv','')
        all_datas['image_id'].append(img_name)
        class_name = name.split('/')[2]
        
        all_datas['label'].append(name2index[class_name])
        for key in data.keys():
            if key.strip() not in all_datas:
                all_datas[key.strip()] = []
            all_datas[key.strip()].append(data[key].values[0])
    db = pd.DataFrame(all_datas)
    db.to_csv('BU3DFE0_1/label/train.csv',index=False)
    # pdb.set_trace()